﻿using System;
using System.Globalization;
using System.Web.UI.WebControls;
using Spring.Web.UI;

namespace bGallery.Web
{
	/// <summary>
	/// User interface masterpage
	/// </summary>
	public partial class bGalleryTemplate : MasterPage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			UpdateTitle();
		}

		/// <summary>
		/// Updates command buttons
		/// </summary>
		/// <param name="e"></param>
		protected override void OnInit(EventArgs e)
		{
			// set non-neutral culture
			if(this.UserCulture.IsNeutralCulture)
			{
				if(!CultureInfo.CurrentUICulture.IsNeutralCulture)
				{
					this.UserCulture = CultureInfo.CurrentUICulture;
				}
				else if (!CultureInfo.CurrentCulture.IsNeutralCulture)
				{
					this.UserCulture = CultureInfo.CurrentCulture;
				}
				else
				{
					this.UserCulture = new CultureInfo("en-US");
				}
			}

			base.OnInit(e);
		}

		/// <summary>
		/// Updates page title according to UserCulture
		/// </summary>
		private void UpdateTitle()
		{
			this.head.Title = GetMessage("defaultTitle") + " - " + this.Page.GetMessage("localTitle");
		}
	}
}
